package com.oocl.euc.core.maintenance.repository;

import com.oocl.euc.core.builder.TeamBuilder;
import com.oocl.euc.core.common.ITTestBase;
import com.oocl.euc.core.maintenance.model.Team;
import com.oocl.euc.core.maintenance.repository.TeamRepository;
import org.junit.*;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;

public class TeamRepositoryIT extends ITTestBase {

    @Autowired
    TeamBuilder teamBuilder;

    @Autowired
    TeamRepository teamRepository;

    @After
    public void tearDown() throws Exception {
        teamRepository.deleteAll();
    }

    @Test
    public void should_return_one_team_when_given_name_TEST_TEAM(){
        Team team = teamBuilder.defaultBuilder()
                .withTeamName("TEST-TEAM")
                .saveToDB();
        List<Team> teams = teamRepository.findByName(team.getName());
        assertTrue(teams.size()>0);
        assertEquals("TEST-TEAM", teams.get(0).getName());
    }

    @Test
    public void should_return_empty_list_when_given_name_TEST_TEAM2(){
        List<Team> teams = teamRepository.findByName("TEST-TEAM2");
        assertTrue(teams.size() == 0);
    }
}
